<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    //21-04-26补充
    //typeof 能检测出六种类型的值  Undefined、Null、Boolean、Number、String、Object function 基本数据类型 
    //console.log(Object.prototype.toString.call(undefined)) // [object Undefined]
    console.log(Object.prototype.toString.call(null)) // [object Null]
    var date = new Date();
    console.log(Object.prototype.toString.call(date)) // [object Date]
    //这是一个 案例了 
    //以下是11种：
    var number = 1;           // [object Number]
    var string = '123';       // [object String]
    var boolean = true;       // [object Boolean]
    var und = undefined;      // [object Undefined]
    var nul = null;           // [object Null]
    var obj = {a: 1}          // [object Object]
    var array = [1, 2, 3];    // [object Array]
    var date = new Date();    // [object Date]
    var error = new Error();  // [object Error]
    var reg = /a/g;           // [object RegExp]
    var func = function a(){}; // [object Function]

    function checkType() {
        for (var i = 0; i < arguments.length; i++) {
            console.log(Object.prototype.toString.call(arguments[i]))
        }
    }
    checkType(number, string, boolean, und, nul, obj, array, date, error, reg, func)

    //console.log(Object.prototype.toString.call(Math)); // [object Math]
    //console.log(Object.prototype.toString.call(JSON)); // [object JSON]
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

   //判断是数组还是对象
   //1. Array.isArray()
        console.log(Array.isArray(arr))      //数组返回true
   //2. constructor
        console.log(arr.construtor === Array)//数据返回true
   //3. Object.prototype.toString.call()
        console.log(Object.prototype.toString.call(arr)) //数组返回object Array

//判断是不是一个空对象？
    //方法1 
    //通过for...in便利属性，如果是空对象返回false，否则返回true
            var Obj = function(obj){
                for(var item in obj){ 
                    return true;  
            }    
                    return false;
            }
    //方法2  es6新增的Object.keys()方法 
            var Obj = function(obj){
            if(Object.keys(obj).length == 0){
                return true     
            }else{
                return false   
            }
            }      
    //方法3
            function checkNullObj(obj) {
                 return Object.keys(obj).length === 0;
            }        
     
        
     
//输入一个值 返回其数据类型  封装应该函数   
    var a = "";
    function type(a){
        return Object.prototype.toString.call(a)
    }
    console.log(type(a))


    //21-04-20 夜补充 
    //判断数据类型 
    //Array
    var a = [];
    console.log(a instanceof Array);    //Array 
    console.log(a.construtor == Array); //true  



    





</script>